package com.yh.workbill.base;

import android.os.Bundle;

import com.yh.workbill.utils.StatusBar;
import com.yh.workbill.view.LoadProgressDialog;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

public abstract class BaseActivity extends AppCompatActivity {

    private LoadProgressDialog loaddingDialog;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        StatusBar.fitSystemBar(this);
        initView(savedInstanceState);
        initJetPack(savedInstanceState);
        initObserve(savedInstanceState);
        initBaseSetting(savedInstanceState);
        initDefaultMethod(savedInstanceState);
        initClick(savedInstanceState);
    }

    public abstract void initView(@Nullable Bundle savedInstanceState);

    public abstract void initJetPack(@Nullable Bundle savedInstanceState);

    public abstract void initObserve(@Nullable Bundle savedInstanceState);

    public abstract void initBaseSetting(@Nullable Bundle savedInstanceState);

    public abstract void initClick(@Nullable Bundle savedInstanceState);

    public abstract void initDefaultMethod(@Nullable Bundle savedInstanceState);


    public void showLoaddingDialog(String content, boolean isCancelable) {
        if (loaddingDialog == null) {
            loaddingDialog = new LoadProgressDialog(BaseActivity.this, content, isCancelable);
        }
        loaddingDialog.showLoadding();
    }

    public void hideLoaddingDialog() {
        if (loaddingDialog != null && loaddingDialog.isShowing()) {
            loaddingDialog.dismissLoadding();
            loaddingDialog = null;
        }
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        hideLoaddingDialog();
    }
}
